<template>
	<view style="padding-bottom: 80upx;">
		<view class=" u-flex padding-lr bg padding-top">
			<view class="u-m-r-10">
				<image :src="avatar" style="width: 100rpx;height: 100rpx;border-radius: 100rpx;"
					@click="goNav('/my/store/index')"></image>
			</view>
			<view class="u-flex-1 u-m-l-10" v-if="!isLogin">
				<view class="u-font-18  text-bold  margin-top-xs">
					<view class="flex align-end">{{userName}}</view>
				</view>
			</view>
			<view v-else class="text-xl u-p-l-20 text-bold" @click="goLogin('/pages/public/login')">
				登录
			</view>
		</view>
		
		<view class="flex align-center padding-left">
			<image src="../../static/images/data.png" style="width: 26upx;height: 26upx;"></image>
			<view class="margin-left-xs flex align-center" style="color: #999999;">
				<view @click="bindData(1)">{{startTime?startTime:'开始时间'}}</view>
				至
				<view @click="bindData(2)">{{endTime?endTime:'结束时间'}}</view>
			</view>
		</view>

		<view class="text-bold text-lg margin-bottom-sm margin-top padding-left">数据统计</view>
		<view class="flex align-center box justify-between text-center">
			<view @click="goNav('/my/store/pingjia')" class="margin-top-sm">
				<text class="text-bold text-xl">{{toDayMoney?toDayMoney:'0'}}</text>
				<view>今日收益</view>
			</view>
			<view @click="goNav('/my/other/cashList')" class="margin-top-sm">
				￥<text class="text-bold text-xl">{{sumMoney?sumMoney:'0'}}</text>
				<view>总收益</view>
			</view>
			<view class="margin-top-sm">
				<text class="text-bold text-xl">{{toDayOrdersCount?toDayOrdersCount:'0'}}</text>
				<view>今日订单</view>
			</view>
			<view class="margin-top-sm">
				<text class="text-bold text-xl">{{ordersCount?ordersCount:'0'}}</text>
				<view>总订单量</view>
			</view>
		</view>
		<view class="padding">
			<view class="text-bold text-lg margin-bottom-sm">订单数据</view>
			<view class="orderbox1">
				<view class="linbix">
					<text class="text-bold text-xl">{{dfwOrdersCount?dfwOrdersCount:'0'}}</text>
					<view class="margin-top-xs">待服务</view>
				</view>
				<view class="linbix">
					<text class="text-bold text-xl">{{cfOrdersCount?cfOrdersCount:'0'}}</text>
					<view class="margin-top-xs">已出发</view>
				</view>
				<view class="linbix">
					<text class="text-bold text-xl">{{ddOrdersCount?ddOrdersCount:'0'}}</text>
					<view class="margin-top-xs">已到达</view>
				</view>
				<view class="linbix">
					<text class="text-bold text-xl">{{jxzOrdersCount?jxzOrdersCount:'0'}}</text>
					<view class="margin-top-xs">服务中</view>
				</view>
				<view class="linbix">
					<text class="text-bold text-xl">{{dplOrdersCount?dplOrdersCount:'0'}}</text>
					<view class="margin-top-xs">待评价</view>
				</view>
				<view class="linbix">
					<text class="text-bold text-xl">{{yqxOrdersCount?yqxOrdersCount:'0'}}</text>
					<view class="margin-top-xs">已取消</view>
				</view>
				<view class="linbix">
					<text class="text-bold text-xl">{{ywcOrdersCount?ywcOrdersCount:'0'}}</text>
					<view class="margin-top-xs">已完成</view>
				</view>
			</view>
		</view>

		<view style="padding: 0upx 30upx;">
			<view class="text-bold text-lg margin-bottom-sm flex justify-between">
				<view>技师申请</view>
				<!-- <view @click="goDetail(1)">
					<text style="color: #666666;font-size: 26upx;margin-right: 10upx;">查看全部</text>
					<image src="../../static/images/my/right.png" style="width: 12upx;height: 20upx;"></image>
				</view> -->
			</view>
			<view class="order">
				<view class="orderbox " @click="goNav('/my/shop/index')">
					<view class="jishi">
						<text class="text-bold text-xl">{{count?count:'0'}}</text>
						<view class="margin-top-xs">全部</view>
					</view>
					<view class="jishi" >
						<text class="text-bold text-xl">{{dshCount?dshCount:'0'}}</text>
						<view class="margin-top-xs">待审核</view>
					</view>
					<view class="jishi">
						<text class="text-bold text-xl">{{ytgCount?ytgCount:'0'}}</text>
						<view class="margin-top-xs">已同意</view>
					</view>
					<view class="jishi">
						<text class="text-bold text-xl">{{yjjCount?yjjCount:'0'}}</text>
						<view class="margin-top-xs">已拒绝</view>
					</view>
				</view>
				<view class="orderbox ">
					<view class="jishi">
						<text class="text-bold text-xl">{{shangCount?shangCount:'0'}}</text>
						<view class="margin-top-xs">上线师傅</view>
					</view>
					<view class="jishi">
						<text class="text-bold text-xl">{{xiaCount?xiaCount:'0'}}</text>
						<view class="margin-top-xs">下线师傅</view>
					</view>
				</view>
			</view>
		</view>

		<!-- <view class="padding">
			<view class="flex">
				<view class="tabbox" v-for="(item,index) in list" :key="index" :class="tabIndex==index?'act':''"
					@click="tabbdex(index)">
					{{item.name}}
				</view>
			</view>

		</view> -->


		<!-- 开始时间 -->
		<u-picker v-model="startshow" mode="time" :params="paramsStart" @confirm="startData"></u-picker>
		<!-- 结束时间 -->
		<u-picker v-model="endshow" mode="time" :params="paramsEnd" @confirm="endData"></u-picker>
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				// ssDW: false,
				// stateName: '休息中',
				avatar: '../../static/logo.png',
				isLogin: true,
				userName: '匿名',

				startshow: false,
				endshow: false,
				paramsStart: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				paramsEnd: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				startTime: '',
				endTime: '',
				toDayMoney: 0, //今日收益
				sumMoney: 0, //总收益
				toDayOrdersCount: 0, //今日订单
				ordersCount: 0, //总订单

				dfwOrdersCount: 0, // 待服务
				cfOrdersCount: 0, // 已出发
				ddOrdersCount: 0, // 已到达
				jxzOrdersCount: 0, // 服务中
				dplOrdersCount: 0, // 待评价
				yqxOrdersCount: 0, // 已取消
				ywcOrdersCount: 0, // 已完成

				count: 0, //全部
				dshCount: 0, //待审核
				ytgCount: 0, //已通过
				yjjCount: 0, //已拒绝
				shangCount: '0', //上线
				xiaCount: 0, //下线

				list: [{
					id: 1,
					name: '签到记录'
				}, {
					id: 2,
					name: '位置记录'
				}],
				tabIndex: 0,

				page: 1,
				limit: 10,
				consortiaId:''
			}
		},
		onLoad() {
			this.userId = uni.getStorageSync('userId')

			// this.status = uni.getStorageSync('status')
			// this.$Request.getT('/app/common/type/247').then(res => { //下单成功
			// 	if (res.code == 0) {
			// 		if (res.data && res.data.value) {
			// 			this.arr.push(res.data.value)
			// 		}
			// 	}
			// })
			// this.$Request.getT('/app/common/type/249').then(res => { //用户完成成功
			// 	if (res.code == 0) {
			// 		if (res.data && res.data.value) {
			// 			this.arr.push(res.data.value)
			// 		}
			// 	}
			// })
			// this.$Request.getT('/app/common/type/309').then(res => { //用户完成成功
			// 	if (res.code == 0) {
			// 		if (res.data && res.data.value) {
			// 			this.arr.push(res.data.value)
			// 		}
			// 	}
			// })
		},
		onShow() {
			//是否开启师傅端实时定位	330
			// this.$Request.get('/app/common/type/330').then(res => {
			// 	if (res.code == 0 && res.data) {
			// 		if (res.data.value != '是') {
			// 			this.ssDW = true;
			// 		} else {
			// 			this.ssDW = false;
			// 		}
			// 	}
			// });

			this.$Request.get('/app/common/type/298').then(res => {
				if (res.code == 0) {
					// #ifdef MP-WEIXIN
					this.$queue.setData('XCXIsSelect', res.data.value);
					// #endif
					// #ifndef MP-WEIXIN
					this.$queue.setData('XCXIsSelect', '是');
					// #endif
					this.XCXIsSelect = this.$queue.getData("XCXIsSelect");
				}
			});
			this.userId = uni.getStorageSync('userId')
			// this.isCashDeposit = uni.getStorageSync('isCashDeposit')
			if (this.userId) {
				this.isLogin = false
				this.getUserInfo()
				this.getJinRiOrder();
				this.getOrder()
				this.getArtificer()
				// this.getcity()
				
				// #ifdef MP-WEIXIN
				//订阅
				if (this.showModal) {
					this.openMsg()
				}
				// #endif
			} else {
				this.isLogin = true
				this.userName = '匿名'
				this.avatar = '../../static/logo.png'
				this.toDayMoney = 0 //今日收益
				this.sumMoney = 0 //总收益
				this.toDayOrdersCount = 0 //今日订单
				this.ordersCoun = 0 //总订单
				this.dfwOrdersCoun = 0, // 待服务
					this.cfOrdersCount = 0 // 已出发
				this.ddOrdersCount = 0 // 已到达
				this.jxzOrdersCount = 0 // 服务中
				this.dplOrdersCount = 0 // 待评价
				this.yqxOrdersCount = 0 // 已取消
				this.ywcOrdersCount = 0 // 已完成

				this.count = 0 //全部
				this.dshCount = 0 //待审核
				this.ytgCount = 0 //已通过
				this.yjjCount = 0 //已拒绝
				this.shangCount = 0 //上线
				this.xiaCount = 0 //下线
			}
		},
		methods: {
			//时间弹框开关
			bindData(index) {
				// if (uni.getStorageSync('sendMsg')) {
				// 	console.log('授权+1')
				// 	wx.requestSubscribeMessage({
				// 		tmplIds: this.arr,
				// 		success(re) {
				// 			console.log(JSON.stringify(re), 111111111111)
				// 			var datas = JSON.stringify(re);
				// 			if (datas.indexOf("accept") != -1) {
				// 				// console.log(re)
				// 			}
				// 		},
				// 		fail: (res) => {
				// 			// console.log(res)
				// 		}
				// 	})
				// }
				// console.log(index, 1111)
				if (index == 1) {
					this.startshow = true
				} else if (index == 2) {
					this.endshow = true

				}
			},
			//开始时间
			startData(e) {
				this.startTime = e.year + '-' + e.month + '-' + e.day
			},
			// 结束时间
			endData(e) {
				this.endTime = e.year + '-' + e.month + '-' + e.day
				this.getJinRiOrder()
				this.getOrder()
			},
			tabbdex(index) {
				this.tabIndex = index
				if(index==0){
					this.page = 1
					this.getqiandao()
				}else if(index==1){
					this.page = 1
					this.getweizhi()
				}
			},
			//数据统计
			getJinRiOrder() {
				let data = {
					startTime: this.startTime,
					endTime: this.endTime
				}
				this.$Request.getT('/app/consortia/selectShopMoneyData', data).then(res => {
					if (res.code == 0) {
						this.toDayMoney = res.data.toDayMoney
						this.sumMoney = res.data.sumMoney
						this.toDayOrdersCount = res.data.toDayOrdersCount
						this.ordersCount = res.data.ordersCount
					}

				})
			},
			//订单统计
			getOrder() {
				let data = {
					startTime: this.startTime,
					endTime: this.endTime
				}
				this.$Request.getT('/app/consortia/selectOrdersShopData', data).then(res => {
					if (res.code == 0) {
						this.dfwOrdersCount = res.data.dfwOrdersCount //待服务
						this.cfOrdersCount = res.data.cfOrdersCount //已出发
						this.ddOrdersCount = res.data.ddOrdersCount //已到达
						this.jxzOrdersCount = res.data.jxzOrdersCount //服务中
						this.yqxOrdersCount = res.data.yqxOrdersCount //已取消
						this.ywcOrdersCount = res.data.ywcOrdersCount //已完成
						this.dplOrdersCount = res.data.dplOrdersCount //待评价
					}

				})
			},
			//技师管理
			getArtificer() {
				let data = {
					startTime: this.startTime,
					endTime: this.endTime
				}
				this.$Request.getT("/app/consortia/selectConsortiaApplyCount",data).then(res => {
					if (res.code == 0) {
						this.count = res.data.count //全部
						this.dshCount = res.data.dshCount //待审核
						this.ytgCount = res.data.ytgCount //已通过
						this.yjjCount = res.data.yjjCount //已拒绝
					}
				});
				this.$Request.getT("/app/consortia/selectArtificerCount").then(res => {
					if (res.code == 0) {
						this.shangCount = res.data.shangCount //上线
						this.xiaCount = res.data.xiaCount //下线
					}
				});
			},
			getcity() {
				let that = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						that.latitude = res.latitude
						that.longitude = res.longitude
						that.getcitys()
					}
				});
			},
			getcitys() {
				this.$Request.get('/app/Login/selectCity?lat=' + this.latitude + '&lng=' + this.longitude).then(res => {
					if (res.code == 0) {
						this.city = res.data.city ? res.data.city : '未知'
					}
				});
			},
			
		
			
			goNav(e, name) {
				console.log(e)
				if (this.userId) {
					uni.navigateTo({
						url: e
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			getUserInfo() {
				this.$Request.get("/app/user/selectUserById").then(res => {
					if (res.code == 0) {
						this.userName = res.data.userName
						this.invitationCode = res.data.invitationCode
						this.avatar = res.data.avatar ? res.data.avatar : '../../static/logo.png'
						this.consortiaId = res.data.consortiaId
						// this.isCashDeposit = res.data.isCashDeposit
						uni.setStorageSync('avatar', res.data.avatar)
						uni.setStorageSync('userName', res.data.userName)
						uni.setStorageSync('invitationCode', res.data.invitationCode)
						// uni.setStorageSync('zhiFuBao', res.data.zhiFuBao)
						// uni.setStorageSync('zhiFuBaoName', res.data.zhiFuBaoName)
						uni.setStorageSync('consortiaId', res.data.consortiaId)
						
					}
				});
			},
			goLogin(e) {
				uni.navigateTo({
					url: e
				})
			},
			// 开启订阅消息
			openMsg() {
				console.log('订阅消息')
				var that = this
				uni.getSetting({
					withSubscriptions: true, //是否获取用户订阅消息的订阅状态，默认false不返回
					success(ret) {
						console.log(ret.subscriptionsSetting, '------------------')
						// if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
						if (ret.subscriptionsSetting.itemSettings) {
							uni.setStorageSync('sendMsg', true)
							uni.openSetting({ // 打开设置页 
								success(rea) {
									console.log(rea.authSetting)
								}
							});
						} else { // 用户没有点击“总是保持以上，不再询问”则每次都会调起订阅消息
							console.log(99999)
							uni.setStorageSync('sendMsg', false)
							uni.showModal({
								title: '提示',
								content: '为了更好的体验,请绑定消息推送',
								confirmText: '确定',
								cancelText: '取消',
								success: function(res) {
									if (res.confirm) {
										wx.requestSubscribeMessage({
											tmplIds: that.arr,
											success(re) {
												console.log(JSON.stringify(re),
													'++++++++++++++')
												var datas = JSON.stringify(re);
												if (datas.indexOf("accept") != -1) {
													console.log(re)
													// uni.setStorageSync('sendMsg', true)
												}
											},
											fail: (res) => {
												console.log(res)
											}
										})
										// uni.setStorageSync('sendMsg', true)
										console.log('确认')
										that.showModal = false
									} else if (res.cancel) {
										console.log('取消')
										// uni.setStorageSync('sendMsg', false)
										that.showModal = true
									}
								}
							})
						}
					}
				})
			},
		},
		
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}

	.bg {
		background-color: #FFFFFF;
	}

	.bgwhite {
		background-color: #FFFFFF;
	}

	.box {
		width: 690upx;
		margin: 0 auto;
		height: 120rpx;
		background: #2FB57A;
		border-radius: 16upx 16upx 0px 0px;
		color: #333333;
		padding: 0upx 30upx;

	}

	.orderbox1 {
		width: 100%;
		background: #FAFAFA;
		border-radius: 16upx;
		display: flex;
		flex-wrap: wrap;
		text-align: center;
		// padding: 0px 30upx;
		padding-top: 30rpx;

		.linbix {
			width: 25%;
			padding-bottom: 30rpx;
		}
	}

	.order {
		border-radius: 16rpx;
		background: #FAFAFA;

		.orderbox {
			width: 100%;
			display: flex;
			text-align: center;
			align-items: center;
			justify-content: start;
			// padding: 0upx 30upx;
			padding-top: 30rpx;

			.jishi {
				width: 25%;
				padding-bottom: 30rpx;
			}
		}
	}

	.xian {
		width: 100%;
		height: 1rpx;
		border: 1rpx solid #f8f8f8;
		margin-top: 20rpx;
	}

	.pintuan_syrs {
		color: #999999;
		font-size: 20upx;
		margin: 20rpx 20rpx 0rpx;
		display: flex;
		padding-right: 18upx;
	}

	.box {
		color: #FFFFFF;
		padding: 40upx 40upx 60upx 40upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		text-align: center;

	}

	.box1 {
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 30rpx;
		margin-top: 30rpx;
	}

	.orderbox {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.guanlibox {
		width: 336upx;
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 30rpx;
	}

	.labe {
		background: #DCF4DC;
		display: inline-flex;
		align-items: center;
		border-radius: 39rpx;
		color: #1A1B1B;
		font-size: 22rpx;
		font-weight: 400;
		width: 110rpx;
		height: 36rpx;
		justify-content: center;
		margin-left: 20rpx;

		text {
			width: 12rpx;
			height: 12rpx;
			background: #20C675;
			border-radius: 50%;
			margin-right: 8rpx;
		}
	}

	.tabbox {
		flex: 1;
		text-align: center;
		padding: 20rpx 0;
	}

	.act {
		background: #DCF4DC;
		color: #20C675;
	}
</style>
